<%@ page import="org.example.DAO.ContentDAO" %>
<%@ page import="org.example.entity.Content" %>
<%@ page import="java.util.List" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
    // 获取电影列表
    ContentDAO contentDAO = new ContentDAO();
    List<Content> movies = contentDAO.getContentsByType(Content.TYPE_MOVIE);
    request.setAttribute("movies", movies);
%>
<%-- 设置页面类型 --%>
<%
    request.setAttribute("pageType", "movie");
%>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>电影 - 内容评级平台</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0/css/all.min.css">
    <style>
        /* 全局样式 */
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
            font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
        }
        :root {
            --primary: #4361ee;
            --secondary: #3f37c9;
            --accent: #4cc9f0;
            --dark: #1d3557;
            --darker: #0d1b2a;
            --light: #f8f9fa;
            --gray: #8d99ae;
            --success: #4caf50;
            --warning: #ff9800;
            --danger: #f44336;
            --card-bg: rgba(29, 53, 87, 0.8);
            --transition: all 0.3s ease;
        }
        body {
            background: linear-gradient(135deg, var(--darker) 0%, var(--dark) 100%);
            color: var(--light);
            min-height: 100vh;
            background-attachment: fixed;
            line-height: 1.6;
        }
        /* 页头样式 */
        header {
            background-color: rgba(13, 27, 42, 0.95);
            backdrop-filter: blur(10px);
            padding: 1rem 2rem;
            position: sticky;
            top: 0;
            z-index: 1000;
            box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
        }
        .header-container {
            max-width: 1400px;
            margin: 0 auto;
            display: flex;
            justify-content: space-between;
            align-items: center;
            flex-wrap: wrap;
        }
        .logo {
            display: flex;
            align-items: center;
            gap: 15px;
            text-decoration: none;
        }
        .logo-icon {
            font-size: 2.5rem;
            color: var(--accent);
        }
        .logo-text {
            font-size: 1.8rem;
            font-weight: 700;
            color: var(--light);
            letter-spacing: 1px;
        }
        .logo-text span {
            color: var(--accent);
        }
        .nav-links {
            display: flex;
            gap: 2rem;
            list-style: none;
        }
        .nav-links a {
            color: var(--light);
            text-decoration: none;
            font-weight: 500;
            font-size: 1.1rem;
            padding: 0.5rem 1rem;
            border-radius: 30px;
            transition: var(--transition);
            display: flex;
            align-items: center;
            gap: 8px;
        }
        .nav-links a:hover, .nav-links a.active {
            background: rgba(67, 97, 238, 0.2);
            color: var(--accent);
        }
        .nav-links a i {
            font-size: 1.2rem;
        }
        .auth-buttons {
            display: flex;
            gap: 1rem;
        }
        .btn {
            padding: 0.7rem 1.5rem;
            border-radius: 30px;
            font-weight: 600;
            font-size: 1rem;
            cursor: pointer;
            transition: var(--transition);
            border: none;
            display: inline-flex;
            align-items: center;
            gap: 8px;
        }
        .btn-primary {
            background: var(--primary);
            color: white;
        }
        .btn-primary:hover {
            background: var(--secondary);
            transform: translateY(-2px);
            box-shadow: 0 4px 15px rgba(67, 97, 238, 0.4);
        }
        .btn-outline {
            background: transparent;
            border: 2px solid var(--primary);
            color: var(--primary);
        }
        .btn-outline:hover {
            background: rgba(67, 97, 238, 0.1);
            transform: translateY(-2px);
        }
        /* 主内容区样式 */
        .main-content {
            max-width: 1400px;
            margin: 2rem auto;
            padding: 0 2rem;
        }
        /* 搜索区域 */
        .search-section {
            text-align: center;
            padding: 3rem 1rem;
            margin-bottom: 3rem;
        }
        .search-section h1 {
            font-size: 2.8rem;
            margin-bottom: 1rem;
            line-height: 1.2;
        }
        .search-section p {
            font-size: 1.2rem;
            color: var(--gray);
            max-width: 700px;
            margin: 0 auto 2rem;
        }
        .search-box {
            max-width: 700px;
            margin: 0 auto;
            display: flex;
            background: var(--card-bg);
            border-radius: 50px;
            overflow: hidden;
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
        }
        .search-input {
            flex: 1;
            padding: 1.2rem 1.5rem;
            border: none;
            background: transparent;
            color: var(--light);
            font-size: 1.1rem;
        }
        .search-input:focus {
            outline: none;
        }
        .search-select {
            padding: 0 1.5rem;
            background: rgba(67, 97, 238, 0.3);
            border: none;
            color: var(--light);
            border-right: 1px solid rgba(255, 255, 255, 0.1);
            appearance: none;
            background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='white' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
            background-repeat: no-repeat;
            background-position: right 1rem center;
            background-size: 1em;
        }
        .search-button {
            padding: 0 2rem;
            background: var(--primary);
            color: white;
            border: none;
            font-weight: 600;
            cursor: pointer;
            transition: var(--transition);
        }
        .search-button:hover {
            background: var(--secondary);
        }
        /* 内容列表样式 */
        .content-section {
            margin-bottom: 3rem;
            padding: 0 1rem;
        }
        .section-header {
            display: flex;
            justify-content: space-between;
            align-items: center;
            margin-bottom: 1.5rem;
        }
        .section-title {
            font-size: 1.8rem;
            font-weight: 700;
            position: relative;
            padding-left: 1rem;
        }
        .section-title::before {
            content: "";
            position: absolute;
            left: 0;
            top: 0;
            height: 100%;
            width: 4px;
            background: var(--accent);
            border-radius: 2px;
        }
        .content-filters {
            display: flex;
            flex-wrap: wrap;
            gap: 1rem;
            margin-bottom: 1.5rem;
        }
        .filter-btn {
            padding: 0.5rem 1.5rem;
            border-radius: 30px;
            background: rgba(255, 255, 255, 0.1);
            cursor: pointer;
            transition: var(--transition);
            font-weight: 500;
        }
        .filter-btn:hover, .filter-btn.active {
            background: rgba(67, 97, 238, 0.2);
            color: var(--accent);
        }
        .content-grid {
            display: grid;
            grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
            gap: 2rem;
        }
        .content-card {
            background: var(--card-bg);
            border-radius: 15px;
            overflow: hidden;
            transition: var(--transition);
            position: relative;
        }
        .content-card:hover {
            transform: translateY(-5px);
            box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
        }
        .content-image {
            width: 100%;
            height: 350px;
            object-fit: cover;
            display: block;
        }
        .content-badge {
            position: absolute;
            top: 1rem;
            right: 1rem;
            background: var(--warning);
            color: var(--darker);
            padding: 0.3rem 0.8rem;
            border-radius: 30px;
            font-weight: 600;
            font-size: 0.9rem;
            display: flex;
            align-items: center;
            gap: 5px;
        }
        .content-info {
            padding: 1.5rem;
        }
        .content-title {
            font-size: 1.3rem;
            font-weight: 700;
            margin-bottom: 0.5rem;
            display: -webkit-box;
            -webkit-line-clamp: 1;
            -webkit-box-orient: vertical;
            overflow: hidden;
        }
        .content-meta {
            color: var(--gray);
            margin-bottom: 1rem;
            font-size: 0.9rem;
        }
        .rating {
            display: flex;
            align-items: center;
            gap: 0.5rem;
            margin-bottom: 1rem;
        }
        .stars {
            color: var(--warning);
            display: flex;
            gap: 2px;
        }
        .rating-value {
            font-weight: 600;
        }
        .content-description {
            margin-bottom: 1.5rem;
            display: -webkit-box;
            -webkit-line-clamp: 3;
            -webkit-box-orient: vertical;
            overflow: hidden;
        }
        .content-actions {
            display: flex;
            justify-content: space-between;
        }
        .action-btn {
            display: flex;
            align-items: center;
            gap: 5px;
            color: var(--light);
            background: rgba(255, 255, 255, 0.1);
            border: none;
            padding: 0.5rem 1rem;
            border-radius: 30px;
            cursor: pointer;
            transition: var(--transition);
        }
        .action-btn:hover {
            background: rgba(255, 255, 255, 0.2);
        }
        /* 分页样式 */
        .pagination {
            display: flex;
            justify-content: center;
            gap: 0.5rem;
            margin-top: 3rem;
        }
        .page-btn {
            width: 2.5rem;
            height: 2.5rem;
            border-radius: 50%;
            display: flex;
            align-items: center;
            justify-content: center;
            background: rgba(255, 255, 255, 0.1);
            cursor: pointer;
            transition: var(--transition);
        }
        .page-btn:hover, .page-btn.active {
            background: rgba(67, 97, 238, 0.2);
            color: var(--accent);
        }
        /* 页脚样式 */
        footer {
            background: rgba(13, 27, 42, 0.95);
            padding: 3rem 2rem 1.5rem;
            margin-top: 3rem;
        }
        .footer-container {
            max-width: 1400px;
            margin: 0 auto;
            display: grid;
            grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
            gap: 2rem;
        }
        .footer-col h3 {
            font-size: 1.3rem;
            margin-bottom: 1.5rem;
            position: relative;
            padding-bottom: 0.5rem;
        }
        .footer-col h3::after {
            content: "";
            position: absolute;
            bottom: 0;
            left: 0;
            width: 50px;
            height: 2px;
            background: var(--accent);
        }
        .footer-links {
            list-style: none;
        }
        .footer-links li {
            margin-bottom: 0.8rem;
        }
        .footer-links a {
            color: var(--gray);
            text-decoration: none;
            transition: var(--transition);
            display: flex;
            align-items: center;
            gap: 8px;
        }
        .footer-links a:hover {
            color: var(--accent);
            padding-left: 5px;
        }
        .footer-links a i {
            width: 20px;
            text-align: center;
        }
        .copyright {
            text-align: center;
            padding-top: 2rem;
            margin-top: 2rem;
            border-top: 1px solid rgba(255, 255, 255, 0.1);
            color: var(--gray);
            font-size: 0.9rem;
        }
        /* 响应式设计 */
        @media (max-width: 992px) {
            .header-container {
                flex-direction: column;
                gap: 1rem;
            }
            .nav-links {
                gap: 0.5rem;
                flex-wrap: wrap;
                justify-content: center;
            }
            .auth-buttons {
                margin-top: 1rem;
            }
            .search-section h1 {
                font-size: 2.2rem;
            }
            .content-grid {
                grid-template-columns: repeat(auto-fill, minmax(250px, 1fr));
            }
        }
        @media (max-width: 768px) {
            .search-box {
                flex-direction: column;
                border-radius: 15px;
            }
            .search-select {
                padding: 1rem 1.5rem;
                border-right: none;
                border-bottom: 1px solid rgba(255, 255, 255, 0.1);
            }
            .search-button {
                padding: 1rem;
            }
            .content-filters {
                flex-wrap: wrap;
            }
        }
        @media (max-width: 480px) {
            .section-header {
                flex-direction: column;
                align-items: flex-start;
                gap: 1rem;
            }
            .content-grid {
                grid-template-columns: 1fr;
            }
        }
    </style>
    <script>
        // 删除内容函数
        function deleteContent(id) {
            if (confirm('确定要删除该电影内容吗？')) {
                fetch('/content/delete?id=' + id, { method: 'POST' })
                    .then(response => {
                        if (response.ok) {
                            // 1. 从页面中移除该内容卡片
                            const card = document.querySelector(`.content-card[data-id="${id}"]`);
                            if (card) {
                                card.style.opacity = '0.5';
                                setTimeout(() => card.remove(), 500);
                            }
                            // 2. 触发内容删除事件
                            const event = new CustomEvent('contentDeleted', { detail: id });
                            window.dispatchEvent(event);
                        }
                    });
            }
        }
        // 监听内容删除事件
        window.addEventListener('contentDeleted', (e) => {
            const id = e.detail;
            const card = document.querySelector(`.content-card[data-id="${id}"]`);
            if (card) {
                card.style.opacity = '0.5';
                setTimeout(() => card.remove(), 500);
            }
        });

        // 搜索电影函数
        function searchMovies() {
            const searchInput = document.querySelector('.search-input').value;
            const category = document.querySelector('.search-select').value;
            console.log(`搜索: ${searchInput}, 分类: ${category}`);
            // 这里可以添加实际的搜索逻辑
        }

        // 过滤电影函数
        function filterMovies(category) {
            const filterBtns = document.querySelectorAll('.filter-btn');
            filterBtns.forEach(btn => {
                btn.classList.remove('active');
            });
            document.querySelector(`.filter-btn[onclick="filterMovies('${category}')"]`).classList.add('active');
            const cards = document.querySelectorAll('.content-card');
            cards.forEach(card => {
                // 这里假设Content实体有getCategory()方法获取分类
                if (category === 'all' || card.dataset.category === category) {
                    card.style.display = 'block';
                } else {
                    card.style.display = 'none';
                }
            });
        }
    </script>
</head>
<body>
<!-- 页头 -->
<%@ include file="navbar.jsp" %>
<!-- 主内容区 -->
<div class="main-content">
    <!-- 搜索区域 -->
    <section class="search-section">
        <h1>探索精彩电影</h1>
        <p>发现来自全球用户的真实评价，找到最适合您的电影</p>
        <div class="search-box">
            <input type="text" class="search-input" placeholder="搜索电影...">
            <select class="search-select">
                <option value="movies">全部电影</option>
                <option value="action">动作</option>
                <option value="comedy">喜剧</option>
                <option value="drama">剧情</option>
                <option value="sci-fi">科幻</option>
                <option value="horror">恐怖</option>
                <option value="animation">动画</option>
            </select>
            <button class="search-button" onclick="searchMovies()"><i class="fas fa-search"></i>搜索</button>
        </div>
    </section>
    <!-- 电影内容区 -->
    <section class="content-section">
        <div class="section-header">
            <h2 class="section-title">热门电影</h2>
            <div class="content-filters">
                <div class="filter-btn active" onclick="filterMovies('all')">全部</div>
                <div class="filter-btn" onclick="filterMovies('action')">动作</div>
                <div class="filter-btn" onclick="filterMovies('comedy')">喜剧</div>
                <div class="filter-btn" onclick="filterMovies('drama')">剧情</div>
                <div class="filter-btn" onclick="filterMovies('sci-fi')">科幻</div>
                <div class="filter-btn" onclick="filterMovies('animation')">动画</div>
            </div>
        </div>
        <div class="content-grid">
            <c:forEach items="${movies}" var="movie">
                <div class="content-card" data-id="${movie.id}" data-category="${movie.category}">
                    <!-- 核心信息区 -->
                    <div class="content-info">
                        <h3 class="content-title">${movie.title}</h3>
                        <!-- 元信息：导演/年份/分类 -->
                        <div class="content-meta">
                            <span><i class="fas fa-user-tie"></i> ${movie.director}</span>
                            <span><i class="fas fa-calendar"></i> ${movie.releaseYear}</span>
                            <span><i class="fas fa-film"></i> ${movie.category}</span>
                        </div>
                        <!-- 电影简介 -->
                        <p class="content-description">${movie.description}</p>
                        <!-- 操作按钮区 -->
                        <div class="content-actions">
                            <button class="action-btn comment"
                                    onclick="window.location.href='movieDetail.jsp?id=${movie.id}'">
                                <i class="far fa-comment-dots"></i> 评论
                            </button>
                            <button class="action-btn favorite"
                                    onclick="addToFavorites('${movie.title}')">
                                <i class="far fa-heart"></i> 收藏
                            </button>
                            <button class="action-btn share"
                                    onclick="shareContent('${movie.title}', 'movie')">
                                <i class="fas fa-share-alt"></i> 分享
                            </button>
                            <!-- 管理员操作按钮 -->
<%--                            <c:if test="${not empty sessionScope.user && sessionScope.user.role == 'admin'}">--%>
<%--                                <button class="action-btn edit"--%>
<%--                                        onclick="window.location.href='/content/edit?id=${movie.id}'">--%>
<%--                                    <i class="fas fa-edit"></i> 编辑--%>
<%--                                </button>--%>
<%--                                <button class="action-btn delete"--%>
<%--                                        onclick="deleteContent('${movie.id}')">--%>
<%--                                    <i class="fas fa-trash-alt"></i> 删除--%>
<%--                                </button>--%>
<%--                            </c:if>--%>
                        </div>
                    </div>
                </div>
            </c:forEach>
            <!-- 无电影时的提示 -->
            <c:if test="${empty movies}">
                <div class="empty-message">
                    <i class="fas fa-film fa-3x"></i>
                    <p>暂无电影内容</p>
                    <a href="content_add.html" class="add-btn">
                        <i class="fas fa-plus"></i> 添加新电影内容
                    </a>
                </div>
            </c:if>
        </div>
        <!-- 分页 -->
        <div class="pagination">
            <div class="page-btn"><i class="fas fa-angle-left"></i></div>
            <div class="page-btn active">1</div>
            <div class="page-btn">2</div>
            <div class="page-btn">3</div>
            <div class="page-btn">4</div>
            <div class="page-btn">5</div>
            <div class="page-btn"><i class="fas fa-angle-right"></i></div>
        </div>
    </section>
</div>
<!-- 页脚 -->
<footer>
    <div class="footer-container">
        <div class="footer-col">
            <h3>关于我们</h3>
            <ul class="footer-links">
                <li><a href="#"><i class="fas fa-info-circle"></i>平台简介</a></li>
                <li><a href="#"><i class="fas fa-users"></i>团队介绍</a></li>
                <li><a href="#"><i class="fas fa-newspaper"></i>新闻动态</a></li>
                <li><a href="#"><i class="fas fa-briefcase"></i>加入我们</a></li>
            </ul>
        </div>
        <div class="footer-col">
            <h3>帮助中心</h3>
            <ul class="footer-links">
                <li><a href="#"><i class="fas fa-question-circle"></i>常见问题</a></li>
                <li><a href="#"><i class="fas fa-envelope"></i>联系我们</a></li>
                <li><a href="#"><i class="fas fa-comment"></i>意见反馈</a></li>
                <li><a href="#"><i class="fas fa-shield-alt"></i>隐私政策</a></li>
            </ul>
        </div>
        <div class="footer-col">
            <h3>内容分类</h3>
            <ul class="footer-links">
                <li><a href="movies.jsp"><i class="fas fa-film"></i>电影</a></li>
                <li><a href="books.html"><i class="fas fa-book"></i>图书</a></li>
                <li><a href="music.html"><i class="fas fa-music"></i>音乐</a></li>
                <li><a href="tv-shows.html"><i class="fas fa-tv"></i>剧集</a></li>
            </ul>
        </div>
        <div class="footer-col">
            <h3>关注我们</h3>
            <div class="social-links">
                <a href="#" class="social-icon"><i class="fab fa-weibo"></i></a>
                <a href="#" class="social-icon"><i class="fab fa-wechat"></i></a>
                <a href="#" class="social-icon"><i class="fab fa-twitter"></i></a>
                <a href="#" class="social-icon"><i class="fab fa-instagram"></i></a>
            </div>
            <p class="subscribe-text">订阅我们的新闻简报</p>
            <div class="subscribe-box">
                <input type="email" placeholder="输入您的邮箱">
                <button class="btn btn-primary">订阅</button>
            </div>
        </div>
    </div>
    <div class="copyright">
        <p>© 2025 内容评级平台 版权所有</p>
    </div>
</footer>
<script>
    // 添加到收藏夹
    function addToFavorites(title) {
        alert(`${title} 已添加到收藏夹!`);
        // 实际应用中，这里可以添加到用户的收藏列表
    }
    // 分享内容
    function shareContent(title, type) {
        alert(`分享 ${title} (${type}) 的链接已复制到剪贴板!`);
        // 实际应用中，这里可以实现复制链接到剪贴板的功能
    }
</script>
</body>
</html>